//
//  ColorTableViewCell.swift
//  Color
//
//  Created by mac on 2018/8/2.
//  Copyright © 2018年 mac. All rights reserved.
//

import UIKit
import ColorArtwork

class ColorTableViewCell: UITableViewCell {
    
    @IBOutlet weak var tTtitle: UILabel!
    @IBOutlet weak var tDetial: UILabel!
    @IBOutlet weak var tDate: UILabel!
    @IBOutlet weak var tImage: UIImageView!
    @IBOutlet weak var tBackGround: UIView!
    
    lazy var context: CIContext = {return CIContext(options: nil)}()

    override func awakeFromNib() {
        super.awakeFromNib()
        
        selectionStyle = .none
    }
    
    func setDataModel(_ model:ColorInfo){
        
        tTtitle.text = model.title
        tDetial.text = model.detial
        tDate.text = model.date
        
        let image:UIImage = UIImage(named: model.image)!
        
        let (back,primary,second,detial) = image.getProminentColors()
        
        tBackGround.backgroundColor = back
        tTtitle.textColor = primary
        tDetial.textColor = second
        tDate.textColor = detial
        
//        let inputImage = CIImage(image: image)
//        let filter = CIFilter(name: "CIGaussianBlur")!
//        filter.setValue(inputImage, forKey:kCIInputImageKey)
//        filter.setValue(3, forKey: kCIInputRadiusKey)
//        let outputCIImage = filter.outputImage!
//        let rect = CGRect(origin: CGPoint.zero, size: image.size)
//        let cgImage = context.createCGImage(outputCIImage, from: rect)
        tImage.image = image
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
